{% comment %}
#    Copyright 2012 New Mexico EPSCoR
#
#    This file is part of Teacher's P.E.T.
#
#    Teacher's P.E.T. is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Teacher's P.E.T. is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Teacher's P.E.T..  If not, see <http://www.gnu.org/licenses/>.
{% endcomment %}

<script type="text/javascript">
    /* <![CDATA[ */
    $(document).ready(function()
    {
		$('#JavascriptOptionsDiv').show();
		$('.FAQ_Question').click(function()
		{
				window.open($(this).attr('href'), "popUp_"+$(this).attr('name'), "width=420,height=315,scrollbars=yes,resizeable"); return false;
		});
    });
    /* ]]> */
    </script>
<script type="text/javascript"> 
	var cal1, cal2;
	$(document).ready(function () {
		cal1 = new Epoch('epoch_popup','popup',document.getElementById('id_start_date'),false);
		cal2 = new Epoch('epoch_popup','popup',document.getElementById('id_end_date'),false);
	});
</script>
<style type="text/css">
	#JavascriptOptionsDiv {display: none;}
	.form_container table.autograde_response,
	.form_container table.activity_template_category
	{
		width: 0;
		display: inline-table;
	}
</style>

{% load files %}
{% load help %}
<div class="form_container">
	{% if TheActivity %}<h1>Edit Activity</h1>
	{% else %}<h1>Create Activity</h1>
	{% endif %}
	
    {# Floating Save Button #}
    <form action="." method="post">{% csrf_token %}
    <button type="submit" class="button SaveButton" name="Save" value="Save" style="position: fixed; bottom: 0px; right: 0px; z-index: 5;" title="Save Current Progress">Save</button>
    
    {# Title #}
    {{QuestionForms.management_form}}
	<table border=0>
	    <tr>
		<th width=1>{{ActivityForm.title.label_tag}}</th><td>{{ActivityForm.title}}<br>{{ActivityForm.title.help_text}}</td><td><span class="errorlist">{% for error in ActivityForm.title.errors %}{{error|escape}} {% endfor %}</span></td>
	    </tr>
	    <tr>
		<th>{{ActivityForm.category.label_tag}}</th><td>{{ActivityForm.category}}<br>{{ActivityForm.category.help_text}}</td><td><span class="errorlist">{% for error in ActivityForm.category.errors %}{{error|escape}} {% endfor %}</span></td>
	    </tr>
	    <tr>
		<th>{{ActivityForm.start_date.label_tag}}</th><td>{{ActivityForm.start_date}}<br>{{ActivityForm.start_date.help_text}}</td><td><span class="errorlist">{% for error in ActivityForm.start_date.errors %}{{error|escape}} {% endfor %}</span></td>
	    </tr>
	    <tr>
		<th>{{ActivityForm.end_date.label_tag}}</th><td>{{ActivityForm.end_date}}<br>{{ActivityForm.end_date.help_text}}</td><td><span class="errorlist">{% for error in ActivityForm.end_date.errors %}{{error|escape}} {% endfor %}</span></td>
	    </tr>
	    <tr>
		<td colspan="100%" class="border-top">
		    <div class="expansion_container">
		    <div class="expansion_title title"><span class="arrow_down"></span>Activity Options</div>
		    <div class="expansion_content{% if not TheActivity %} expansion_open{% endif %}">
		    <table>
		    <tr>
			<th>{{ActivityForm.activity_type.label_tag}}</th><td colspan="2">{{ActivityForm.activity_type}}</td>
		    </tr>
		    <tr>
			<th>{{ActivityForm.activity_results_type.label_tag}}</th><td colspan="2">{{ActivityForm.activity_results_type}}</td>
		    </tr>
		    <tr>
			<th>{{ActivityForm.randomize_questions.label_tag}}</th><td>{{ActivityForm.randomize_questions}}<br>{{ActivityForm.randomize_questions.help_text}}</td><td><span class="errorlist">{% for error in ActivityForm.randomize_questions.errors %}{{error|escape}} {% endfor %}</span></td>
		    </tr>
		    <tr>
			<th>{{ActivityForm.allow_html.label_tag}}</th><td>{{ActivityForm.allow_html}}<br>{{ActivityForm.allow_html.help_text}}</td><td><span class="errorlist">{% for error in ActivityForm.allow_html.errors %}{{error|escape}} {% endfor %}</span></td>
		    </tr>
		    <tr>
			<th>{{ActivityForm.allow_late_submissions.label_tag}}</th><td>{{ActivityForm.allow_late_submissions}}<br>{{ActivityForm.allow_late_submissions.help_text}}</td><td><span class="errorlist">{% for error in ActivityForm.allow_late_submissions.errors %}{{error|escape}} {% endfor %}</span></td>
		    </tr>
		    <tr>
			<th>{{ActivityForm.submissions_allowed.label_tag}}</th><td>{{ActivityForm.submissions_allowed}}<br>{{ActivityForm.submissions_allowed.help_text}}</td><td><span class="errorlist">{% for error in ActivityForm.submissions_allowed.errors %}{{error|escape}} {% endfor %}</span></td>
		    </tr>
		    {% if TheActivity %}<tr><th><label>Total Points</label></th><td>{{TheActivity.total_points}}</td></tr>{% endif %}
		    </table>
			<div class="expansion_footer footer"><span class="arrow_up"></span></div>
		    </div>
		    </div>
		</td>
	    </tr>
	    
	    <tr>
		<td colspan="100%" class="border-top">
		    <div class="expansion_container">
		    <div class="expansion_title title"><span class="arrow_down"></span>Collection/Menu Options</div>
		    <div class="expansion_content{% if not TheActivity %} expansion_open{% endif %}">
		    <table>
			{% if TheActivity %}
			<tr>
			    <th>{{ActivityForm.subactivities.label_tag}}</th><td>{{ActivityForm.subactivities}}<br>{{ActivityForm.subactivities.help_text}}</td><td><span class="errorlist">{% for error in ActivityForm.subactivities.errors %}{{error|escape}} {% endfor %}</span></td>
			</tr>
			{% endif %}
			<tr>
			    <th>{{ActivityForm.show_collection_menu.label_tag}}</th><td>{{ActivityForm.show_collection_menu}}<br>{{ActivityForm.show_collection_menu.help_text}}</td><td><span class="errorlist">{% for error in ActivityForm.show_collection_menu.errors %}{{error|escape}} {% endfor %}</span></td>				
			</tr>
			<tr>
			    <th>{{ActivityForm.order_number.label_tag}}</th><td>{{ActivityForm.order_number}}<br>{{ActivityForm.order_number.help_text}}</td><td><span class="errorlist">{% for error in ActivityForm.order_number.errors %}{{error|escape}} {% endfor %}</span></td>
			</tr>
			<tr>
			    <th>{{ActivityForm.main_menu.label_tag}}</th><td>{{ActivityForm.main_menu}}<br>{{ActivityForm.main_menu.help_text}}</td><td><span class="errorlist">{% for error in ActivityForm.main_menu.errors %}{{error|escape}} {% endfor %}</span></td>
			</tr>
			<tr>
			    <th>{{ActivityForm.display_title.label_tag}}</th><td>{{ActivityForm.display_title}}<br>{{ActivityForm.display_title.help_text}}</td><td><span class="errorlist">{% for error in ActivityForm.display_title.errors %}{{error|escape}} {% endfor %}</span></td>
		        </tr>
			<tr>
			    <th>{{ActivityForm.is_public.label_tag}}</th><td>{{ActivityForm.is_public}}<br>{{ActivityForm.is_public.help_text}}</td><td><span class="errorlist">{% for error in ActivityForm.is_public.errors %}{{error|escape}} {% endfor %}</span></td>
			</tr>
		    </table>
			<div class="expansion_footer footer"><span class="arrow_up"></span></div>
		    </div>
		    </div>
		</td>
	    </tr>
	    {% if TheActivity %}
		<tr><td colspan="100%" class="border-top">
		<div class="expansion_container">
		<div class="expansion_title title"><span class="arrow_down"></span>Files</div>
		<div class="expansion_content">
		<a class="button smallbutton" href="{% course_url management app='files' command='manage' arguments=TheActivity.get_content_and_id %}">Go to file management</a>
		<iframe class="resize_needed fullheight" frameBorder="0" border="0" width="100%" src="{% course_url management app='files' command='manage' arguments=TheActivity.get_content_and_id iframe='iframe'%}">
		{% load files %}
		{% render_file_list for TheActivity %}
		<p><b>Note:</b> This save button is used for any changes made to file titles and descriptions (instead of the one at the bottom of the page)</p>
		</iframe>
		<div class="expansion_footer footer"><span class="arrow_up"></span></div>
		</div>
		</div>
		</td></tr>
	    {% endif %}
	    <tr>
		<td colspan="100%" class="border-top">
		    <div class="expansion_container">
		    <div class="expansion_title title"><span class="arrow_down"></span>Templates</div>
		    <div class="expansion_content">
			{% get_admin_help_list for templates as help_list %}
				{% if help_list %}
				<span class="popup_container floatright">
				    <span class="popup_title"><a><img src="{{STATIC_URL}}images/help.png" height=32></a></span>
					<span class="left_over_popup">
						{% if help_list %}
						<p>{{'Questions related to Templates:'|spacify}}</p>
						<ul>
						{% for faq in help_list %}
								<li><a class="FAQ_Question" name="{{faq.question_link}}" href="{{faq.url}}" target="_blank">{{faq.question|spacify}}</a></li>
						{% endfor %}
						</ul>
						{% else %}
						<p>{{'There is no help yet for this'|spacify}}</p>
						{% endif %}
					</span>
				</span>
				{% endif %}
			{% if Templates %}
			{% regroup Templates by category as Templates %}
			{% for template_category in Templates %}
			<table class="activity_template_category" border="0"><tr><th class="border-bottom"><h3>{{template_category.grouper}}</h3></th></tr>
			{% for template in template_category.list %}
			<tr><td>
				<span class="popup_container">
					<span class="popup_title"><u>{{template.title}}</u></span>
					<span class="right_up_popup border-all activity-edit-template-popup">
						<hr>
						<h3>{{template.title}}</h3>
						{% if template.description %}<i>{{template.description}}</i>{% endif %}
						<hr>
						{% if template.example %}Example:<br>{% render template.example %}{% endif %}
						<hr>
						<button type="submit" class="button" name="Template" value="{{template.id}}" title="Appends this template to the current activity">Append</button>
					</span>
				</span>&nbsp;&nbsp;
			</td></tr>
			{% endfor %}
			</table>
			{% endfor %}
			{% else %}
			<p>There are currently no Templates. You can add one in the <a href="{% course_url management app='activities' %}">Activities Management tab</a>.</p>
		    {% endif %}
		    <div class="expansion_footer footer"><span class="arrow_up"></span></div>
		    </div>
		    </div>
		</td>
	    </tr>
	    <tr><td colspan="100%" class="border-top"></td></tr>
	    <tr><td colspan="100%">
		<table><tr>
		<th><a name="activitycontent">{{ActivityForm.content.label_tag|spacify}}</a></th>
		<td>
				{{ActivityForm.content}}
				<br>
				{{ActivityForm.content.help_text}}
		</td>
		<td class="fullwidth">
				<span class="errorlist">{% for error in ActivityForm.content.errors %}{{error|escape}} {% endfor %}</span>
				{% get_admin_help_list for activities.content as help_list %}
				{% if help_list %}
				<span class="popup_container floatright">
				    <span class="popup_title"><a><img src="{{STATIC_URL}}images/help.png" height=32></a></span>
					<span class="left_over_popup">
						{% if help_list %}
						<p>{{'Questions related to Activity content:'|spacify}}</p>
						<ul>
						{% for faq in help_list %}
								<li><a class="FAQ_Question" name="{{faq.question_link}}" href="{{faq.url}}" target="_blank">{{faq.question|spacify}}</a></li>
						{% endfor %}
						</ul>
						{% else %}
						<p>{{'There is no help yet for this'|spacify}}</p>
						{% endif %}
					</span>
				</span>
				{% endif %}
		</td>
		</tr>
		</table>
		</td>
	    </tr>
	</table>
    <hr>
    {% for form,responses in QuestionForms %}
        {% for field in form.hidden_fields %}{{field}}{% endfor %}
        <div class="expansion_container">
	    <div class="expansion_title title"><span class="arrow_down"></span>
		    <a name="section{{form.instance.section_number}}">Question {{form.section_number}}</a>
			<button type="submit" class="button DeleteButton smallbutton floatright" name="DeleteSection" value="{{forloop.counter}}"  title="Delete This Section">X</button>
	    </div>
	    <div class="expansion_content{% if not TheActivity %} expansion_open{% endif %}">
				{% get_admin_help_list for activities.questions as help_list %}
				{% if help_list %}
				<span class="popup_container floatright">
				    <span class="popup_title"><a><img src="{{STATIC_URL}}images/help.png" height=32></a></span>
					<span class="left_over_popup">
						{% if help_list %}
						<p>{{'Questions related to Activity questions:'|spacify}}</p>
						<ul>
						{% for faq in help_list %}
								<li><a class="FAQ_Question" name="{{faq.question_link}}" href="{{faq.url}}" target="_blank">{{faq.question|spacify}}</a></li>
						{% endfor %}
						</ul>
						{% else %}
						<p>{{'There is no help yet for this'|spacify}}</p>
						{% endif %}
					</span>
				</span>
				{% endif %}
		<table>
		<tr>
		    <td>{{form.total_points.label_tag}}</td><td>{{form.total_points}}<br>{{form.total_points.help_text}}</td><td>{{form.total_points.errors}}</td>
		</tr>
		<tr>
		    <td>{{form.type.label_tag}}</td><td>{{form.type}}<br>{{form.type.help_text}}</td><td>{{form.type.errors}}</td>
		</tr>
		<tr>
		    <td>{{form.question.label_tag}}</td><td>{{form.question}}<br>{{form.question.help_text}}</td><td>{{form.question.errors}}</td>
		</tr>
		<tr>
		    <td>{{form.start_date.label_tag}}</td><td>{{form.start_date}}<br>{{form.start_date.help_text}}</td><td>{{form.start_date.errors}}</td>
		</tr>
		<tr>
		    <td>{{form.end_date.label_tag}}</td><td>{{form.end_date}}<br>{{form.end_date.help_text}}</td><td>{{form.end_date.errors}}</td>
		</tr>
		<tr>
		    <td>{{form.choices.label_tag}}</td>
		    <td><span class="popup_container">
		        <span class="popup_title"><u>For multiple choice questions, enter choices here</u></span>
			<span class="right_up_popup">{{form.choices}}<br>{{form.choices.help_text}}</span>
			</span>
		    </td>
		    <td>{{form.choices.errors}}</td>
		</tr>
		<tr>
		    <td>{{form.allowable_extensions.label_tag}}</td>
		    <td><span class="popup_container"><span class="popup_title"><u>For file uploads, enter allowable extensions here</u></span>
			<span class="right_up_popup">{{form.allowable_extensions}}<br>{{form.allowable_extensions.help_text}}</span>
			</span>
		    </td>
		    <td>{{form.allowable_extensions.errors}}</td>
		</tr>
		<tr><th colspan="3" class="border-top"><button type="submit" class="button AddButton floatleft" name="AddResponse" value="{{form.instance.section_number}}"  title="Add An Autograde Response">+</button><h2>Autograde Responses:</h2></th></tr>
		{% if responses %}
		<tr><td colspan="100%">
		    {% for response in responses %}
			<table cellpadding="0" cellspacing="0" class="autograde_response">
			<tr>
			    <th class="border-top border-left">Points:</th>
			    <td class="border-top">{{response.points}}</td>
			    <td class="border-top border-right"><button type="submit" class="button DeleteButton smallbutton" name="DeleteResponse" value="{{form.instance.section_number}};{{response.instance.id}}"  title="Delete This Response">X</button></td>
			</tr>
			<tr><th class="border-left">Response:</th><td class="border-right" colspan="2">{{response.response}}</td></tr>
			<tr><th class="border-bottom border-left">Notes:</th><td class="border-bottom border-right" colspan="2">{{response.notes}}</td></tr>
			</table>
		    {% endfor %}
		</td></tr>
		{% endif %}
		<tr><td colspan="100%" class="border-bottom"></td><td colspan="100%" class="border-bottom"></td></tr>
		</tr>
		</table>
		<div class="expansion_footer footer"><span class="arrow_up"></span></div>
	    </div>
	</div>
    <div class="clear"></div>
{% endfor %}
<table>
    <tr>
	<td class="Buttons">
	<button type="submit" class="button AddButton floatleft" name="NewQuestion" value="" title="Add A New Question">+</button>
	<button type="submit" class="button AddButton floatleft" name="NewQuestion5" value="" title="Add 5 New Questions">+5</button>
	<button type="submit" class="button SaveButton floatleft" name="Save" value="SaveEdit" title="Save and Continue Editing">Save and Continue</button>
        <button type="submit" class="button SaveButton floatleft" name="Save" value="SaveReturn" title="Save and Return to Activity Management">Save and Return</button>
        <a class="button SaveButton" href="{% course_url management app='activities' %}">Cancel</a>
	</td></tr>
</table>
    </form>
</div>

